// pages/subpackage//pages/crm/editWorkerOrder/editWorkerOrder.js
var app = getApp();
var formUp = true;
var myData = new Date();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        serviceType: [], //业务类型
        businessid: [], //提交的业务类型
        tyepIndex: 0, //
        outList: [{ name: '是', value: 1 }, { name: '否', value: 2, checked: 'true' }], //是否外接
        transferList: [{ name: '是', value: 1 }, { name: '否', value: 2, checked: 'true' }], //是否新建移机工单
        isOutserver: false, //是否是外接订单
        seeList: [{ name: '是', value: 1, checked: 'true' }, { name: '否', value: 2 }], //是否对用户可见
        add_ress: '', //详细地址
        ch_latitude: '', //当前
        ch_longitude: '', //当前
        service_address: '', //移机地址
        chNew_latitude: '', //移机
        chNew_longitude: '', //移机
        valueName: [], //设置回显选择的地址(name)
        getAreaMsg: {}, //选择的地址信息
        moveAMsg: {}, //移机新装地址
        cusDetail: '', //选择客户的信息
        user_id: '', //选择--用户--ID
        user_name: '', //选择--用户--姓名
        device_no: '', //选择--缴费器--编号
        equipment_id: '', //选择--缴费器--ID
        havAddorder: false, //是否有新增工单(此处仅为了展示提示))
        isNewClothes: false, //是否是新装工单
        isRepair: false, //是否是维修工单
        isDemolition: false, //是否是拆机工单
        isRelocation: false, //是否是移机工单

        isSurvey: false, //是否是勘测工单
        go_home_Date: '', //上门日期
        timeArr: [{ time_id: "", format: "请选择时间段" }], //时间段数组
        timeIndex: 0, //上门时间段下标
        sceneArr: [{ id: "", name: "请选择服务场景" }], //服务场景数组
        sceneIndex: 0, //服务场景下标
        cookertypeArr: [{ id: "", name: "请选择炉具类型" }], //炉具类型数组
        cookertypeIndex: 0, //炉具类型下标
        cooker_purchase_time: '', // 炉具购买时间
        code_no: '', //户号

        sign_date: '', //自定义装机时间
        explainList: [{ id: '', name: "请选择讲解人", phone: "" }], //讲解人列表
        explainIndex: 0,
        produceList: [{ equipments_id: '', equipments_name: '请选择产品名称' }],
        produceIndex: 0, //产品名称
        produceNewIndex: 0, //新产品
        problemList: [{ problem_id: '', problem_desc: '请选择主要问题' }], //
        problemIndex: 0, //问题列表
        work_order_id: '', //需要修改的工单id
        workerDetail: {}, //工单详情

      today_data: myData.getFullYear() + '-' + (myData.getMonth() + 1) + '-' + myData.getDate(),//获取今天日期
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        if (options.work_order_id) {
            this.setData({
                work_order_id: options.work_order_id
            })
            this.getWorkorderDetail(options.work_order_id);
        }
        // 初始化动画变量
        var that = this;
        that.headidnew = this.selectComponent("#addressNewid");
        that.headid = this.selectComponent("#addressid"); //引入地址
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {
        if (this.data.user_id) {
            console.log('选择的用户信息', this.data.user_id, this.data.user_name)
            this.getCustomerDetail(this.data.user_id); //获取选中用户详情
        }
    },
    //跳转客户列表选择
    navExchange() {
        wx.navigateTo({
            url: '../exchange/exchange?way=2', //交换也可进客户列表页面 交换1 新增工单传的2
        })
    },
    //自定义列表
    defineSetMeal() {
        wx.showModal({
            title: '该功能正在开发中',
            content: '请移驾PC端使用该功能',
            showCancel: false,
            confirmColor: '#DF0101'
        })
        return false;
        //
        wx.navigateTo({
            url: '../defineSetMeal/defineSetMeal', //自定义套餐
        })
    },
    //跳转户号列表选择
    codeManage() {
      if (!this.data.user_id) {
        app.showToast('请先选择用户信息');
        return false
      }
      wx.navigateTo({
        url: '../codeManage/codeManage?choose=true&userid=' + this.data.user_id,
      })
    },
    //跳转缴费器列表选择
    deviceManage() {
        let that = this;
        if (!that.data.user_id) {
          app.showToast('请先选择用户信息');
          return false
        }
        if (!that.data.code_no) {
          app.showToast('请先选择户号');
          return false
        }
        wx.navigateTo({
          url: '../deviceManage/deviceManage?chose=true&userid=' + that.data.user_id + '&code_no=' + that.data.code_no,
        })
    },
    //选择业务类型
    serviceTypeChange(e) {
        const that = this;
        const serviceType = that.data.serviceType;
        const values = e.detail.value;
        const lenJ = values.length;
        //判断是否是新装工单(其他类型则不能选择)反之也如此,values[0]==3新装工单只能独立选择(根据原来逻辑来写的);
        if (values[0] == 3) {
            serviceType.forEach(function(item, i) {
                if (item.business_type_id == 3) {
                    item.disabled = false;
                    item.checked = true;
                    that.setData({ isNewClothes: true, isUrge: false, isCore: false, isDemolition: false, isRelocation: false, isUrge: false }); //除了新装工单
                } else {
                    item.disabled = true;
                }
            })
        } else {
            serviceType.forEach(function(item, i) {
                item.checked = false;
                if (item.business_type_id == 3) {
                    item.disabled = true;
                    if (lenJ <= 0) {
                        item.disabled = false;
                        that.setData({ isNewClothes: false }); //不是新装
                    }
                    item.checked = false;
                } else {
                    //that.setData({ isNewClothes: false, isUrge: false, isCore: false, isDemolition: false, isRelocation: false, isUrge:false});//不是新装
                    item.disabled = false; //重置所有 之后再有的值中循环选中
                    values.forEach(function(its, k) {
                        if (item.business_type_id == its) {
                            item.checked = true;
                            if (its == 1) {
                                that.setData({ isUrge: true });
                            } else if (its == 2) {
                                that.setData({ isCore: true });
                            } else if (its == 4) {
                                that.setData({ isDemolition: true });
                            } else if (its == 5) {
                                that.setData({ isRelocation: true });
                            } else if (its == 6) {
                                that.setData({ isRepair: true });
                            }
                        } else {
                            console.log('数据结果', item.business_type_id, its, item.checked);
                            if (!item.checked) {
                                if (item.business_type_id == 1) {
                                    that.setData({ isUrge: false });
                                } else if (item.business_type_id == 2) {
                                    that.setData({ isCore: false });
                                } else if (item.business_type_id == 4) {
                                    that.setData({ isDemolition: false });
                                } else if (item.business_type_id == 5) {
                                    that.setData({ isRelocation: false });
                                } else if (item.business_type_id == 6) {
                                    that.setData({ isRepair: false });
                                }
                            }
                        }
                    });
                }
            })
            if (lenJ <= 0) {
                that.setData({ isNewClothes: false, isRepair: false, isCore: false, isDemolition: false, isRelocation: false, isUrge: false }); //都不选
            }
        }
        //serviceType  values
        // 获取所有id集合 觉得这种方式要简单些,但是不想改了
        //let arr1Ids = values.map(item => Number(item));
        //const result = serviceType.filter(item => !arr1Ids.includes(item.business_type_id));//不同的
        //const result2 = serviceType.filter(item => arr1Ids.includes(item.business_type_id));//相同的
        //console.log('不同的', result, '相同', result2, arr1Ids);
        console.log('工单业务类型', serviceType, values);
        this.setData({
            serviceType,
            businessid: values
        })
    },
    //搜索_____________开始时间
    startDateChange: function(e) {
        this.setData({
          sign_date: e.detail.value
        })
    },
    //搜索_____________开始时间
    endDateChange: function(e) {
        this.setData({
            pac_expire_date: e.detail.value
        })
    },
    //选择是否外接
    radioChange1: function(e) {
        var outList = this.data.outList;
        outList.forEach(function(item, index) {
            if (item.value == e.detail.value) {
                item.checked = true;
            } else {
                item.checked = false;
            }
        });
        this.setData({
            outList,
            isOutserver: e.detail.value == 1 ? true : false
        })
    },
    //是否新建移机装工单
    radioTransferChange: function(e) {
        var transferList = this.data.transferList;
        transferList.forEach(function(item, index) {
            if (item.value == e.detail.value) {
                item.checked = true;
            } else {
                item.checked = false;
            }
        });
        this.setData({
            transferList
        })
    },
    //是否對用戶可见
    isSeeChange: function(e) {
        var seeList = this.data.seeList;
        seeList.forEach(function(item, index) {
            if (item.value == e.detail.value) {
                item.checked = true;
            } else {
                item.checked = false;
            }
        });
        this.setData({
            seeList
        })
    },
    // 选工单状态
    bindPickerChange: function(e) {
        this.setData({
            tyepIndex: e.detail.value
        })
    },
    //选择讲解人
    bindExplainChange: function(e) {
        this.setData({
            explainIndex: e.detail.value
        })
    },
    //选择产品列表
    bindProduceChange: function(e) {
        this.setData({
            produceIndex: e.detail.value,
        })
    },
    //选择新产品列表(移机中改变的)
    bindProduceNewChange: function(e) {
        this.setData({
            produceNewIndex: e.detail.value
        })
    },
    //常见问题列表
    bindProblemChange: function(e) {
        this.setData({
            problemIndex: e.detail.value
        })
    },
    //打开地图选择
    openAddress() {
        var that = this;
        this.headid.startAddressAnimation(true);
    },
    //确定接受
    getSure(data) {
        console.log('确定事件获取地址', data);
        var that = this;
        let [province_code, city_code, area_code] = data.detail.areaId;
        let [province, city, area] = data.detail.areaName;
        that.setData({
            getAreaMsg: data.detail
        })
    },
    //打开地图选择
    openNewAddress() {
        var that = this;
        this.headidnew.startAddressAnimation(true);
    },
    //确定接受
    getNewSure(data) {
        console.log('确定事件获取地址', data);
        var that = this;
        let [province_code, city_code, area_code] = data.detail.areaId;
        let [province, city, area] = data.detail.areaName;
        that.setData({
            moveAMsg: data.detail
        })
    },

    //选择地址
    openAeraFun() {
        var that = this;
        wx.chooseLocation({
            success: function(res) {
                console.info(res);
                that.setData({
                    add_ress: res.name,
                    ch_latitude: res.latitude,
                    ch_longitude: res.longitude,
                })
            },
        })
    },

    //选择地址(移机)
    openAeraNewFun() {
        var that = this;
        wx.chooseLocation({
            success: function(res) {
                console.info(res);
                that.setData({
                    service_address: res.name ? res.name : res.address,
                    chNew_latitude: res.latitude,
                    chNew_longitude: res.longitude,
                })
            },
        })
    },

    //获取工单业务类型
    getBusinessType(getArr) {
        var that = this;
        app.ajax({
            url: 'api/Workorder/getBusinessType',
            url_type: 2,
            data: {},
            success: function(res) {
                if (res.data.code == 1000) {
                    var serviceType = res.data.data;
                    serviceType.forEach(function(item, index) {
                        item.checked = false;
                        item.disabled = true;
                        getArr.forEach(function(its, ids) {
                            if (item.business_type_id == its) {
                                item.checked = true;
                                 if (its == 3) {
                                    that.setData({ isNewClothes: true });
                                } else if (its == 4) {
                                    that.setData({ isDemolition: true });
                                } else if (its == 5) {
                                    that.setData({ isRelocation: true });
                                } else if (its == 6) {
                                    that.setData({ isRepair: true });
                                } else if (its == 7) {
                                    that.setData({ isSurvey: true });
                                }
                            }
                        })
                    });
                    that.setData({
                        serviceType
                    })
                } else {
                    app.showToast(res.data.msg);
                }

            }
        })
    },
    //获取选中的客户信息
    getCustomerDetail(id) {
        var that = this;
        app.ajax({
            url: 'api/Customer/getCustomerDetail',
            url_type: 2,
            data: {
                user_id: id
            },
            success: function(res) {
                if (res.data.code == 1000) {
                    var detialMsg = res.data.data;
                    that.setData({
                        cusDetail: detialMsg,
                    })
                    that.statisticsworkordernum(id); //判断是否有新增登工单
                } else {
                    app.showToast(res.data.msg);
                }

            }
        })
    },
    //判断是否有新增登工单
    statisticsworkordernum(id) {
        var that = this;
        app.ajax({
            url: 'api/workorder/statisticsworkordernum',
            url_type: 2,
            data: {
                business_id: 3,
                user_id: id
            },
            success: function(res) {
                if (res.data.code == 1000) {
                    that.setData({
                        havAddorder: res.data.data == 1 ? true : false
                    })
                } else {
                    app.showToast(res.data.msg);
                }

            }
        })
    },
    //获取讲解人列表
    getExplainers(explais) {
        var that = this;
        app.ajax({
            url: 'api/Workorder/getExplainers',
            url_type: 2,
            data: {},
            success: function(res) {
                if (res.data.code == 1000) {
                    var explainList = that.data.explainList;
                    var explainIndex = that.data.explainIndex;
                    explainList = explainList.concat(res.data.data);
                    explainList.forEach(function(item, index) {
                        if (explais == item.id) {
                            explainIndex = index
                        }
                    })
                    that.setData({
                        explainList,
                        explainIndex
                    })
                } else {
                    app.showToast(res.data.msg);
                }
            }
        })
    },
    //获取产品列表
    getProductList(id, newid) {
        var that = this;
        app.ajax({
            url: 'api/Equipments/getList',
            url_type: 2,
            data: {},
            success: function(res) {
                if (res.data.code == 1000) {
                    var produceList = that.data.produceList;
                    var produceIndex = that.data.produceIndex;
                    var produceNewIndex = that.data.produceNewIndex;
                    produceList = produceList.concat(res.data.data);
                    produceList.forEach(function(item, index) {
                        if (id == item.equipments_id) {
                            produceIndex = index
                        }
                        if (newid == item.equipments_id) {
                            produceNewIndex = index;
                        }
                    })
                    console.log('>>>>>', produceList, produceIndex, produceNewIndex);
                    that.setData({
                        produceList,
                        produceIndex,
                        produceNewIndex
                    })
                } else {
                    app.showToast(res.data.msg);
                }
            }
        })
    },
    // 获取问题列表
    getProblemsList(id) {
        var that = this;
        app.ajax({
            url: 'api/Workorder/getProblem',
            url_type: 2,
            data: {},
            success: function(res) {
                if (res.data.code == 1000) {
                    var problemList = that.data.problemList;
                    var problemIndex = that.data.problemIndex;
                    problemList = problemList.concat(res.data.data);
                    problemList.forEach(function(item, index) {
                        if (id == item.problem_id) {
                            problemIndex = index
                        }
                    });
                    that.setData({
                        problemList,
                        problemIndex
                    })
                } else {
                    app.showToast(res.data.msg);
                }

            }
        })
    },
    //获取工单详情
    getWorkorderDetail(work_order_id) {
        var that = this;
        app.ajax({
            url: 'api/Workorder/getWorkorderDetail',
            url_type: 2,
            data: {
                work_order_id
            },
            success: function(res) {
                if (res.data.code == 1000) {
                    var workerDetail = res.data.data;
                    var orderMsg = workerDetail.order_info;
                    var orderData = workerDetail.order_data;
                    var orderEq = workerDetail.eq_info;
                    var currEqMsg = {};
                    orderEq.forEach(function(item, index) {
                        if (item.work_order_id == work_order_id) {
                            currEqMsg = item
                        }
                    });
                    that.setData({
                        workerDetail: workerDetail,
                        businessid: orderMsg.business_id,
                        user_id: orderMsg.user_id,
                        user_name: orderMsg.username,
                        device_no: currEqMsg.device_no,
                        equipment_id: currEqMsg.equipment_id,
                        getAreaMsg: {
                            areaName: [orderMsg.province, orderMsg.city, orderMsg.area],
                            areaId: [orderMsg.province_code, orderMsg.city_code, orderMsg.area_code]
                        },
                        valueName: [orderMsg.province, orderMsg.city, orderMsg.area],
                        add_ress: orderMsg.service_address,
                        ch_latitude: orderMsg.lat,
                        ch_longitude: orderMsg.lng,
                        moveAMsg: {
                            areaName: [orderMsg.move_province, orderMsg.move_city, orderMsg.move_area],
                            areaId: [orderMsg.move_province_code, orderMsg.move_city_code, orderMsg.move_area_code]
                        },
                        service_address: orderMsg.move_address,
                        chNew_latitude: orderMsg.move_lat,
                        chNew_longitude: orderMsg.move_lng,

                        sign_date: orderMsg.sign_date,
                        go_home_Date: orderMsg.appointment_time[0],
                        cooker_purchase_time: orderMsg.cooker_information.cooker_purchase_time,
                    })
                    that.getCustomerDetail(orderMsg.user_id); //获取选中用户详情  处理回显
                    that.getBusinessType(orderMsg.business_id); //获取工单业务类型  处理回显
                    that.getExplainers(orderMsg.explainer); //获取讲解人列表 处理回显
                    if (orderMsg.equipments_id || orderMsg.move_change_equipments) { //先判断是否有order_id
                        that.getProductList(orderMsg.equipments_id, orderMsg.equipments_id); //获取产品列表 处理回显
                    }

                    that.isToUser(orderMsg.is_to_user); //是否对用户可见 回显
                    that.getProblemsList(orderMsg.problem_key_id[0]); //获取主要问题列表
                    that.isOutget(orderMsg.is_circumscribed);
                    that.newAddOrder(orderMsg.is_new_word_order); //是否新建移机工单

                    that.getRangeTime(orderMsg.appointment_time_id); //获取时间段列表
                    that.getSceneList(orderMsg.cooker_information.scene_type); //获取服务场景列表
                    that.getCookertypeList(orderMsg.cooker_information.cooker_type); //获取炉具类型列表

                } else {
                    app.showToast(res.data.msg);
                }
            }
        })
    },
    //是否对用户可见
    isToUser(num) {
        var seeList = this.data.seeList;
        seeList.forEach(function(item, index) {
            if (item.value == num) {
                item.checked = true;
            } else {
                item.checked = false;
            }
        });
        this.setData({
            seeList
        })
    },
    //是否外接
    isOutget(is_circumscribed) {
        var outList = this.data.outList;
        outList.forEach(function(item, index) {
            if (item.value == is_circumscribed) {
                item.checked = true;
            } else {
                item.checked = false;
            }
        });
        this.setData({
            outList,
            isOutserver: is_circumscribed
        })
    },
    //是否新产品名称
    newAddOrder(is_new_word_order) {
        var transferList = this.data.transferList;
        transferList.forEach(function(item, index) {
            if (item.value == is_new_word_order) {
                item.checked = true;
            } else {
                item.checked = false;
            }
        });
        this.setData({
            transferList
        })
    },

  // 获取预约时间范围
  getRangeTime(id) {
    let that = this;
    app.ajax({
      url: 'Common/Common/getRangeTime',
      data: {},
      success: function (res) {
        let timeIndex = that.data.timeIndex;
        let timeArr = that.data.timeArr;
        timeArr = timeArr.concat(res.data.data.time);
        timeArr.forEach(function (item, index) {
          if (id == item.time_id) {
            timeIndex = index
          }
        });
        that.setData({
          timeArr: timeArr,
          timeIndex: timeIndex
        })
      }
    })
  },
  //选择上门日期
  gohomeDateChange(e) {
    this.setData({
      go_home_Date: e.detail.value
    })
  },
  //选择上门时间段
  timeRangeChange(e) {
    this.setData({
      timeIndex: e.detail.value
    })
  },
  //获取服务场景列表
  getSceneList(id) {
    let that = this;
    app.ajax({
      url: 'api/Common/getSearchConfig',
      url_type: 2,
      data: { config_name: 'scene_type' },
      success: function (res) {
        let sceneIndex = that.data.sceneIndex;
        let tempArr = that.data.sceneArr;
        tempArr = tempArr.concat(res.data.data);
        tempArr.forEach(function (item, index) {
          if (id == item.id) {
            sceneIndex = index
          }
        });
        that.setData({
          sceneArr: tempArr,
          sceneIndex: sceneIndex
        })
      }
    })
  },
  //选择服务场景
  sceneChange(e) {
    this.setData({
      sceneIndex: e.detail.value
    })
  },
  //获取炉具类型列表
  getCookertypeList(id) {
    let that = this;
    app.ajax({
      url: 'api/Common/getSearchConfig',
      url_type: 2,
      data: { config_name: 'cooker_type' },
      success: function (res) {
        let cookertypeIndex = that.data.cookertypeIndex;
        let tempArr = that.data.cookertypeArr;
        tempArr = tempArr.concat(res.data.data);
        tempArr.forEach(function (item, index) {
          if (id == item.id) {
            cookertypeIndex = index
          }
        });
        that.setData({
          cookertypeArr: tempArr,
          cookertypeIndex: cookertypeIndex
        })
      }
    })
  },
  //选择炉具类型
  cookertypeChange(e) {
    this.setData({
      cookertypeIndex: e.detail.value
    })
  },
  //选择炉具购买时间
  cookerPurchaseTimeChange(e) {
    this.setData({
      cooker_purchase_time: e.detail.value
    })
  },

    // 检测表单
    checkForm(isTrue, message) {
        if (isTrue) {
            return { isReturn: isTrue, message }
        } else {
            return false;
        }
    },
    // 提交表单
    saveForm(e) {
        let formData = e.detail.value;
        let { isReturn, message } = this.checkForm(formData.account == '', '请输入账号') || this.checkForm(formData.password == '', '请输入密码');
        if (isReturn) {
            app.showToast(message);
            return;
        }
    },
    //取消
    cancelFun() {
        wx.navigateBack({
            delta: 1
        })
    },
    //提交的表单数据 api/Workorder/add
    formSubmit(e) {

        var that = this,
            pageData = that.data,
            cusDetail = that.data.cusDetail,
            formData = e.detail.value;
        var explainData = pageData.explainList[pageData.explainIndex];
        var problemData = pageData.problemList[pageData.problemIndex];
        var produceData = pageData.produceList[pageData.produceIndex];
        var newprduData = pageData.produceList[pageData.produceNewIndex];
        let { isReturn, message } =
        that.checkForm(cusDetail == '', '请先选择用户信息') ||
            that.checkForm(formData.contacts == '', '联系人不能为空') ||
            that.checkForm(formData.contactsPhone == '', '联系人电话不能为空') ||
            that.checkForm(pageData.businessid.length <= 0, '请先选择业务类型') ||
            that.checkForm(cusDetail == '', '请选择用户信息') ||
            that.checkForm(pageData.go_home_Date == '', '请选择上门日期') ||
            that.checkForm(pageData.timeIndex == 0 && pageData.timeArr.length > 0, '请选择上门时间段');
        if (isReturn) {
            app.showToast(message);
            return;
        }
        // 新装
        if (pageData.isNewClothes && !pageData.isOutserver) {
            let { isReturn, message } =
            that.checkForm(pageData.produceIndex == 0 && pageData.isNewClothes, '请选择产品') ||
                that.checkForm(pageData.getAreaMsg.length == 0, '请选改造地址') ||
                that.checkForm(pageData.ch_latitude == '' || pageData.ch_longitude == '' || formData.user_address == '', '请先定位位置信息');
            if (isReturn) {
                app.showToast(message);
                return;
            }
        }

        //勘测
        if (pageData.isSurvey && !pageData.isOutserver) {
          let { isReturn, message } =
            that.checkForm(pageData.produceIndex == 0, '请选择产品') ||
            that.checkForm(pageData.getAreaMsg.length == 0, '请选改造地址') ||
            that.checkForm(pageData.ch_latitude == '' || pageData.ch_longitude == '' || formData.user_address == '', '请先定位位置信息');
          if (isReturn) {
            app.showToast(message);
            return;
          }
        }

        //维修 外接
        if (pageData.isRepair && !pageData.isOutserver) {
            let { isReturn, message } =
                that.checkForm(pageData.equipment_id == '', '请选择缴费器信息') ||
                that.checkForm(problemData.problem_id == '', '请选择主要问题') ||
                that.checkForm(formData.problem == '', '请输入问题描述');
            if (isReturn) {
                app.showToast(message);
                return;
            }
        }

        //拆机
        if (pageData.isDemolition && !pageData.isOutserver) {
            let { isReturn, message } =
              that.checkForm(pageData.equipment_id == '', '请选择缴费器信息');
            if (isReturn) {
                app.showToast(message);
                return;
            }
        }

        //移机 外接
        if (pageData.isRelocation && !pageData.isOutserver) {
            let { isReturn, message } =
                that.checkForm(pageData.equipment_id == '', '请选择缴费器信息') ||
                that.checkForm(newprduData.equipments_id == '', '请选择新产品名称') ||
                that.checkForm(pageData.moveAMsg.length == 0, '请选新改造地址') ||
                that.checkForm(pageData.chNew_latitude == '' || pageData.chNew_longitude == '' || formData.service_address == '', '请先定位位置信息');
            if (isReturn) {
                app.showToast(message);
                return;
            }
        }

        var submitData = {
            contract_id: pageData.workerDetail.order_info.contract_id,
            work_order_id: pageData.work_order_id,
            _username: formData._username,
            user_id: cusDetail.user_id,
            equipments_type: '',
            contacts: formData.contacts,
            contact_number: formData.contactsPhone,
            businessid: pageData.businessid,
            explainer: explainData.id,
            equipments_id: produceData.equipments_id,
            equipmentsname: produceData.equipments_id, //这是 id
            sign_date: formData.sign_date, //自定义改造时间
            is_collect_money: formData.is_collect_money,
            is_circumscribed: formData.is_circumscribed,
            is_new_word_order: formData.is_new_word_order,
            equipment_id: pageData.equipment_id,
            device_no: pageData.device_no,
            question: [problemData.problem_id] || [],
            questionMore: formData.problem,
            moveprovince: pageData.moveAMsg ? pageData.moveAMsg.areaName[0] : '',
            movecity: pageData.moveAMsg ? pageData.moveAMsg.areaName[1] : '',
            movearea: pageData.moveAMsg ? pageData.moveAMsg.areaName[2] : '',
            province_id: pageData.moveAMsg ? pageData.moveAMsg.areaId[0] : '',
            city_id: pageData.moveAMsg ? pageData.moveAMsg.areaId[1] : '',
            area_id: pageData.moveAMsg ? pageData.moveAMsg.areaId[2] : '',
            moveEquipmentsName: newprduData.equipments_id || '', //这是移机
            service_address: formData.service_address,
            userprovince: pageData.getAreaMsg ? pageData.getAreaMsg.areaName[0] : '',
            usercity: pageData.getAreaMsg ? pageData.getAreaMsg.areaName[1] : '',
            userarea: pageData.getAreaMsg ? pageData.getAreaMsg.areaName[2] : '',
            province_code: pageData.getAreaMsg ? pageData.getAreaMsg.areaId[0] : '',
            city_code: pageData.getAreaMsg ? pageData.getAreaMsg.areaId[1] : '',
            area_code: pageData.getAreaMsg ? pageData.getAreaMsg.areaId[2] : '',
            user_address: formData.user_address,
            is_to_user: formData.is_to_user,
            remarks: formData.remarks,
            lat: pageData.ch_latitude,
            lng: pageData.ch_longitude,
            move_lat: pageData.chNew_latitude,
            move_lng: pageData.chNew_longitude,

            go_home_time: pageData.go_home_Date, //上门日期
            appointment_time_id: pageData.timeIndex == 0 ? '' : pageData.timeArr[pageData.timeIndex].time_id, //上门时间段下标
            scene_type: pageData.sceneArr[pageData.sceneIndex].id, //服务场景
            cooker_type: pageData.cookertypeArr[pageData.cookertypeIndex].id, //炉具类型
            cooker_brand: formData.cooker_brand, //炉具品牌
            cooker_model_number: formData.cooker_model_number, //炉具型号
            cooker_num: formData.cooker_num, //炉具数量
            expected_renovation_num: formData.expected_renovation_num, //预计改造数量
            gas_fee: formData.gas_fee, //近三月燃气均价
            cooker_purchase_time: pageData.cooker_purchase_time, //炉具购买时间
        }

        console.log('提交的表单数据', submitData);
        if (!formUp) {
            app.showToast('请勿重复提交该表单');
            return false;
        }
        formUp = false;
        app.ajax({
            url: 'api/Workorder/edit',
            url_type: 2,
            data: submitData,
            success: function(res) {
                if (res.data.code == 1000) {

                    app.showToast(res.data.msg);
                    setTimeout(function() {
                        wx.navigateBack({
                            delta: 1
                        })
                    }, 1000);
                } else {
                    app.showToast(res.data.msg);
                }

                setTimeout(function() {
                    formUp = true;
                }, 600);
            }
        })
    },

})
